<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="receive_search"
      :searchData="userSearchData"
      :isHaveExport="false"
      @toAdd="add_data"
      :isHavePagination="true"
      :isShow="false"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list"
          :data1="info"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
          @selection-change="handleSelectionChange"
        >
          <!-- <el-table-column type="selection" class="tc" width="35"></el-table-column> -->
          <!-- <el-table-column label="排序" sortable :sort-method="sorta" align="center" width="80">
            <template slot-scope="scope">
              <div>
                <el-input @change="sortNew(scope.$index, scope.row)" v-enterNumber v-model="scope.row.sort" autocomplete="off" size="small">
                </el-input>
              </div>
            </template>
          </el-table-column> -->
          <el-table-column label="老用户最小助力比例" min-width="120">
            <template slot-scope="scope">
              {{ scope.row.old_minimum_ratio }}
            </template>
          </el-table-column>
          <el-table-column label="老用户最大助力比例" min-width="120">
            <template slot-scope="scope">
              {{ scope.row.old_maximum_ratio }}
            </template>
          </el-table-column>
          <el-table-column label="新用户最小助力比例" min-width="120">
            <template slot-scope="scope">
              {{ scope.row.new_minimum_ratio }}
            </template>
          </el-table-column>
          <el-table-column label="新用户最大助力比例" min-width="120">
            <template slot-scope="scope">
              {{ scope.row.new_maximum_ratio }}
            </template>
          </el-table-column>
          <el-table-column label="阶段数" min-width="120">
            <template slot-scope="scope">
              {{ scope.row.stages }}
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="editbtn(scope.row)"
                  type="primary"
                  >查看详情</el-button
                >
                <!-- <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="defbtn(scope.row)"
                  type="primary"
                  >查看详情</el-button
                > -->
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  type="danger"
                  @click="deletebtn(scope.row.id)"
                  >删除</el-button
                >
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog
      :close-on-click-modal="false"
      :title="edit"
      class="tl size_13"
      width="800px"
      :visible.sync="dialogFormVisible">
      <el-form :model="live_single" ref="form" label-width="160px">
        <el-form-item label="老用户最小助力比例：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="live_single.old_minimum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="老用户最大助力比例：" prop="avatar">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="live_single.old_maximum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="新用户最小助力比例：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="live_single.new_minimum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="新用户最大助力比例：">
          <el-col :span="12">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="live_single.new_maximum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="editlive(live_single)"
            >编 辑</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :title="'新老用户助力比例详情'"
      :visible.sync="dioForm"
      width="40%"
      center
    >
      <el-form :model="info" ref="form">
        <el-form-item label="老用户最小助力比例：">
          <el-col :span="16">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="info.old_minimum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="老用户最大助力比例：" prop="avatar">
          <el-col :span="16">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="info.old_maximum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="新用户最小助力比例：">
          <el-col :span="16">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="info.new_minimum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="新用户最大助力比例：">
          <el-col :span="16">
            <el-input
              type="text"
              :rows="6"
              clearable
              placeholder="请输入"
              v-model="info.new_maximum_ratio"
              autocomplete="off"
            ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item class="tc">
          <el-button
            :loading="$store.state.isLoading"
            type="primary"
            @click="editlive(live_single)"
            >编 辑</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
// import { GiftSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import uploadpic from "@/components/page/pic/up_pic";
export default {
  data() {
    return {
      // userSearchData: GiftSearchData,
      current: "",
      shows: false,
      is_edit: false,
      dialogFormVisible: false,
      live_single: {
        old_minimum_ratio: "",
        old_maximum_ratio: "",
        new_minimum_ratio: "",
        new_maximum_ratio: "",
      },
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      multipleSelection: [],
      showCity: true,
      dioForm: false,
      info:[],
      data: {
        title: "",
      },
      edit: "",
    };
  },
  components: {
    uploadpic,
  },
  methods: {
    getIs(val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      params.show = val;
      this.editlive(params);
    },
   
    getShow(val) {
      this.shows = val;
    },
    getSend(row) {
      this.live_single.username = row.username;
      this.live_single.uid = row.id;
    },
    xzshop() {
      this.shows = true;
    },
    sorta(a, b) {
      return b - a;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    deletebtn(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
          this.$api.getHelps.delHelpUser({ id: id }).then((res) => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    add_data() {
      this.edit = "添加"
      this.live_single = {
        old_minimum_ratio: "",
        old_maximum_ratio: "",
        new_minimum_ratio: "",
        new_maximum_ratio: "",
      };
      this.is_edit = false;
      this.dialogFormVisible = true;
    },
    onSuccess(pic) {
      console.log(pic);
      this.live_single.piclink = pic;
    },
    getIs(val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      params.show = val;
      this.editlive(params);
    },

    editlive(item) {
      var params = {};

      if (this.is_edit == false) {
        params = item;
        params.vid = this.$route.query.id;
        this.$api.getHelps.addHelpUser(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        params = item;
        params.vid = this.$route.query.id;
        this.$api.getHelps.editHelpUser(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },
    editbtn(item) {
        this.edit = "详情";
      this.is_edit = true;
      this.live_single = item;
      this.dialogFormVisible = true;
    },
    defbtn(item) {
      this.dioForm = true;
      this.getproList(item.id)
      // this.info = item;
      
      // this.dialogFormVisible = true;
    },
    receive_search(obj) {
      console.log(666666, obj);
      this.searchAll = obj;
      this.getNewsAll(obj);
      //   this.$router.push(this.$route.path + "?page=" + 1);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      params.vid = this.$route.query.id;
      this.$api.getHelps.getHelpUserList(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
     getproList(item){
      this.loading = true;
      var params = {};
      // data1 = data1 || {};
      // params = data1;
      params.id = item
      this.$api.getHelps.defHelpUser(params).then((res) => {
        if (res.data.code == 200) {
          this.info = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload() {
      this.getNewsAll(this.searchAll);
    },
  },
  beforeCreate() {},
  created() {
    this.getNewsAll();
    // this.getproList()
  },

  computed: {},
  watch: {
    $route() {
      var params = this.searchAll;
      params.page = this.$route.query.page || 1;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
      this.currentPage = Number(this.$route.query.page) || 1;
    },
  },
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
